package cn.edu.tsinghua.cic.ccss.task;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.forten.dic.util.EhcacheHelper;
import org.forten.utils.system.LogUtil;
import org.springframework.stereotype.Component;

@Component("shortMsgFlagInit")
public class ShortMsgFlagInit {

	private static Logger log = Logger.getLogger(ShortMsgFlagInit.class);
	private static final String INIT_MSG = "初始化短信定时任务执行标记完成";

	@Resource
	private EhcacheHelper ehcacheHelper;

	@PostConstruct
	public void initTaskFlag() {
		ehcacheHelper.writeToCache("taskExecuteFlagCache", "shortMsgFlag", 0);
		LogUtil.info(log, INIT_MSG);
		getFlag("shortMsgFlag");
	}

	public int getFlag(String key) {
		int flag = (Integer) ehcacheHelper.getValue("taskExecuteFlagCache", key);
		LogUtil.debug(log, "taskExecuteFlagCache：key[%s],value[%d]", key,flag);
		return flag;
	}

	public void setFlag(String key, int value) {
		ehcacheHelper.writeToCache("taskExecuteFlagCache", key, value);
	}
}
